//
//  Array+Extension.swift
//  Tools
//
//  Created by Felix Yuan on 2020/3/17.
//  Copyright © 2020 Hangzhou Shichuo Information Technology Co, Ltd. All rights reserved.
//

import Foundation

// MARK: 删除数组元素

extension Array where Element: Equatable {
    /// 根据数组元素删除
    ///
    /// - Parameter object: 要删除的对象
    public mutating func remove(object: Element) {
        if let index = firstIndex(of: object) {
            remove(at: index)
        }
    }
}

public extension Array where Element: Hashable {
    func removingDuplicates() -> [Element] {
        var addedDict = [Element: Bool]()

        return filter {
            addedDict.updateValue(true, forKey: $0) == nil
        }
    }

    mutating func removeDuplicates() {
        self = self.removingDuplicates()
    }
}

